//
//  LineCell.swift
//  BaseSwift
//
//  Created by gh on 2019/10/2.
//  Copyright © 2019 ghwang. All rights reserved.
//

import UIKit

class GoodsCell: UITableViewCell {

    let containerView = UIView()
    let photo = UIImageView()
    let nameLab = UILabel()
    let introLab = UILabel()
    let userIcon = UIImageView()
    let nickNameLab = UILabel()
    
    var tagsView:STTagsView? = nil

    

    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.containerView.sd_cornerRadius = 8
        self.backgroundColor = UIColor.white
        containerView.backgroundColor = UIColor.white
        self.selectionStyle = .none
        


        
        let tempV = UIView()
        tempV.backgroundColor = UIColor.white
        self.contentView.addSubview(tempV)
        let _ = tempV.sd_layout()?.spaceToSuperView(UIEdgeInsets(top: 0, left: 25, bottom: 16, right: 25))
        tempV.updateLayout()
        // shadowCode
        tempV.layer.shadowColor = UIColor.lineColor.cgColor
        tempV.layer.shadowOffset = CGSize(width: 1, height: 5)
        tempV.layer.shadowRadius = 2.5
        tempV.layer.shadowOpacity = 0.35

        tempV.addSubview(self.containerView)
        let _ = self.containerView.sd_layout()?.spaceToSuperView(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
        self.containerView.sd_cornerRadius = 8

        
        
        
        containerView.addSubview(photo)
        photo.backgroundColor = UIColor.cccColor
        let height = (KScreenWidth-50)*9/16

        let _ = photo.sd_layout()?.heightIs(CGFloat(height))?.widthRatioToView(containerView,1)?.topSpaceToView(containerView,0)
        
        containerView.addSubview(nameLab)
        nameLab.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight(rawValue: 0.2))
        nameLab.textColor = UIColor.textTitleColorBlack
        nameLab.text = "阿根廷、南极午夜阳号18天之旅"
        let _ = nameLab.sd_layout()?.leftSpaceToView(containerView,16)?.heightIs(22)?.rightSpaceToView(containerView,16)?.topSpaceToView(photo,5)
        
        containerView.addSubview(introLab)
        introLab.font = UIFont.smallFont
        introLab.textColor = UIColor.textPlaceHolderColor
        introLab.text = "一年仅此一次概要"
        let _ = introLab.sd_layout()?.leftSpaceToView(containerView,16)?.heightIs(16)?.rightSpaceToView(containerView,16)?.topSpaceToView(nameLab,3)
        
        
        introLab.updateLayout()
        containerView.updateLayout()
        tagsView = STTagsView.tagView(withFrame: CGRect(x: 8, y: introLab.frame.maxY+10, width: containerView.width-40, height: 15), tagsArray: ["打卡阿根廷网红地","一天","线路"], textColor: UIColor.GP_Blue_Color, textFont: UIFont .systemFont(ofSize: 10), normalTagBackgroundColor: UIColor.backgroundColor, tagBorderColor: UIColor.GP_Blue_Color, contentInsets: UIEdgeInsets(top: 10, left: 5, bottom: 10, right: 5), labelContentInsets: UIEdgeInsets(top: 3, left: 3, bottom: 3, right: 3), labelHorizontalSpacing: 5, labelVerticalSpacing: 5)
        containerView.addSubview(tagsView!)
        
        
        

        
        let bottomView = UIView()
        bottomView.isHidden = true
        containerView.addSubview(bottomView)
        let _ =  bottomView.sd_layout()?.widthRatioToView(containerView,1)?.heightIs(35)?.bottomSpaceToView(containerView,1)
        
        bottomView.addSubview(userIcon)
        let _  = userIcon.sd_layout()?.widthIs(20)?.heightIs(20)?.centerYEqualToView(bottomView)?.leftSpaceToView(bottomView,16)
        
        bottomView.addSubview(nickNameLab)
        nickNameLab.font = UIFont.smallerLessthanFont
        nickNameLab.textColor = UIColor.textPlaceHolderColor
        nickNameLab.text = "昵称"
        let _  = nickNameLab.sd_layout()?.heightIs(20)?.centerYEqualToView(bottomView)?.leftSpaceToView(userIcon,5)
        nickNameLab.setSingleLineAutoResizeWithMaxWidth(155)
        
        let commentBtn = UIButton()
        commentBtn.setImage(UIImage(named: "评论1"), for: .normal)
        commentBtn.titleLabel?.font = UIFont.smallerLessthanFont
        commentBtn.setTitleColor(UIColor.textPlaceHolderColor, for: .normal)
        commentBtn.setTitle("22", for: .normal)
        bottomView.addSubview(commentBtn)
        let _ = commentBtn.sd_layout()?.rightSpaceToView(bottomView,5)?.centerYEqualToView(bottomView)?.widthIs(55)
        
        
        let _ = commentBtn.imageView?.sd_layout()?.widthIs(15)?.heightIs(15)?.leftSpaceToView(commentBtn,0)?.centerYEqualToView(commentBtn)
        
        let _ = commentBtn.titleLabel?.sd_layout()?.heightIs(15)?.leftSpaceToView(commentBtn.imageView,5)?.widthIs(45)?.centerYEqualToView(commentBtn)
        commentBtn.titleLabel?.textAlignment = .left
        
        let favBtn = UIButton()
        favBtn.setImage(UIImage(named: "收藏"), for: .normal)
        favBtn.titleLabel?.font = UIFont.smallerLessthanFont
        favBtn.setTitleColor(UIColor.textPlaceHolderColor, for: .normal)
        favBtn.setTitle("18", for: .normal)
        bottomView.addSubview(favBtn)
        let _ = favBtn.sd_layout()?.rightSpaceToView(commentBtn,30)?.centerYEqualToView(bottomView)?.widthIs(55)
        
        
        let _ = favBtn.imageView?.sd_layout()?.widthIs(15)?.heightIs(15)?.rightSpaceToView(favBtn,0)?.centerYEqualToView(favBtn)
        
        let _ = favBtn.titleLabel?.sd_layout()?.heightIs(15)?.leftSpaceToView(favBtn.imageView,5)?.widthIs(45)?.centerYEqualToView(favBtn)
        favBtn.titleLabel?.textAlignment = .left
        
        
        
        
        
    }
    func setModel(mod:ProductVo){
        
        photo.sd_setImage(with: URL(string:mod.pdtImg!), placeholderImage: UIImage(named: "holder_big"), options: .lowPriority) { (img, B, C, D) in
            
            SDImageCache.shared.store(img, forKey: mod.pdtImg ?? "", toDisk: true) {
                
            }
        }
        nameLab.text = mod.pdtName!.replacingOccurrences(of: "#", with: " ")
        
        tagsView?.removeFromSuperview()
        let tags = mod.tags?.split(string: ",")
        tagsView = STTagsView.tagView(withFrame: CGRect(x: 13, y: introLab.frame.maxY-15, width: containerView.width-40, height: 15), tagsArray: tags, textColor: UIColor.GP_Blue_Color, textFont: UIFont .systemFont(ofSize: 10), normalTagBackgroundColor: UIColor.backgroundColor, tagBorderColor: UIColor.GP_Blue_Color, contentInsets: UIEdgeInsets(top: 10, left: 5, bottom: 10, right: 5), labelContentInsets: UIEdgeInsets(top: 3, left: 3, bottom: 3, right: 3), labelHorizontalSpacing: 5, labelVerticalSpacing: 5)
        containerView.addSubview(tagsView!)
        introLab.text = ""
        
        userIcon.sd_setImage(with: URL(string: "http"), placeholderImage: UIImage(named: "默认头像"), options: .lowPriority) { (A, B, C, D) in
            
        }
        containerView.layer.shadowColor = UIColor.lightGray.cgColor
        containerView.layer.shadowOffset = CGSize(width: 3, height: 10)
        containerView.layer.shadowOpacity = 0.4
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
